import axios from 'axios'

const instance = axios.create({
  baseURL: 'http://localhost:8090',
  // baseURL: 'http://39.106.224.218:8090',
  timeout: 20000
})

instance.interceptors.request.use(config => {
  // 判断是否存在token，如果存在的话，则每个http header都加上token
  const token = sessionStorage.getItem('AUTH_TOKEN')
  // eslint-disable-next-line no-unused-expressions
  token ? config.headers.AUTH_TOKEN = token : ''
  return config
}, error => {
  return Promise.reject(error)
})

export default instance
